# Definition for a  binary tree node
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

def makeTree(nums, start, end):
	if start > end:
		return None
	root = TreeNode(nums[(start+end)/2])
	root.left = makeTree(nums, start, (start+end)/2-1)
	root.right = makeTree(nums, (start+end)/2+1, end)
	return root

class Solution:
	# @param num, a list of integers
	# @return a tree node
	def sortedArrayToBST(self, num):
		length = len(num)
		ans = makeTree(num, 0, length-1)
		return ans

def printTree(tree):
	if tree is not None:
		print(tree.val)
		if tree.left is not None:
			printTree(tree.left)
		if tree.right is not None:
			printTree(tree.right)

if __name__ == '__main__':
	n = [0,1,2,3,4,5]
	so = Solution()
	r = so.sortedArrayToBST(n)
	printTree(r)